import cv2 as cv
import numpy as np


def pyrdown_demo(img):
    pyr_imgs= []
    level = 3
    temp = img.copy()
    for l in range(level):
        dst = cv.pyrDown(temp)
        cv.imshow('pyr'+str(l),dst)
        pyr_imgs.append(dst)
        temp = dst.copy()
    return pyr_imgs


def pyrup_demo(img):
    pyr_imgs = pyrdown_demo(img)
    level = len(pyr_imgs)
    for i in range(level -1 ,-1, -1):
        if (i - 1) < 0:
            expand = cv.pyrUp(pyr_imgs[i], dstsize=pyr_imgs[i - 1].shape[:2])
            lapls = np.subtract(expand.shape[:2], pyr_imgs[i].shape[:2])
        else:
            expand = cv.pyrUp(pyr_imgs[i],dstsize=pyr_imgs[i-1].shape[:2])
            lapls = np.subtract(expand.shape[:2],pyr_imgs[i].shape[:2])
        cv.imshow('lapls:'+ str(lapls),expand)


src = cv.imread('messi5.jpg', 1)
cv.namedWindow('demo',cv.WINDOW_AUTOSIZE)
cv.imshow('demo', src)
pyrup_demo(src)
cv.waitKey(0)
cv.destroyWindow('demo')